package com.lz.gmall.web.controller;

import com.lz.gamll.feign.search.GoodsFeignClient;
import com.lz.gmall.search.dto.SearchParamDTO;
import com.lz.gmall.search.vo.SearchResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class SearchController {

    @Autowired
    private GoodsFeignClient goodsFeignClient;

    @GetMapping("/list.html")
    public String list(SearchParamDTO searchParamDTO, Model model){

        SearchResponseVo searchResponseVo = goodsFeignClient.search(searchParamDTO).getData();

        // 把数据存储到model数据模型中
        model.addAttribute("searchParam" , searchResponseVo.getSearchParam()) ;
        model.addAttribute("trademarkParam" , searchResponseVo.getTrademarkParam()) ;
        model.addAttribute("propsParamList" , searchResponseVo.getPropsParamList()) ;
        model.addAttribute("trademarkList" , searchResponseVo.getTrademarkList()) ;
        model.addAttribute("attrsList" , searchResponseVo.getAttrsList()) ;
        model.addAttribute("goodsList" , searchResponseVo.getGoodsList()) ;
        model.addAttribute("urlParam" , searchResponseVo.getUrlParam()) ;
        model.addAttribute("pageNo" , searchResponseVo.getPageNo()) ;
        model.addAttribute("totalPages" , searchResponseVo.getTotalPages()) ;
        model.addAttribute("orderMap" , searchResponseVo.getOrderMap()) ;

        return "list/index";
    }
}
